package com.zj.small.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class UserPython {
    public static String chatBot(String data){
        Process proc;
        String line = null;
        StringBuilder result = new StringBuilder();
        try {
//            proc = Runtime.getRuntime().exec("cmd /c D:\\javaProject\\small\\file.bat");
            String[] args1 = new String[] {"D:\\miniconda\\envs\\lmmini\\python.exe", "D:\\javaProject\\vue\\ChatLM-mini-Chinese\\cli_demo2.py", data};
            proc = Runtime.getRuntime().exec(args1);
            //用输入输出流来截取结果
            BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream(), StandardCharsets.UTF_8));

            while ((line=in.readLine())!=null){
                System.out.println(line);
                result.append(line);
            }
            System.out.println("chatBot over");
            in.close();
            proc.waitFor();
        } catch (IOException | InterruptedException e) {

            e.printStackTrace();
        }
        if (result.toString().isEmpty()) {
            return "我是一个参数很少的AI模型，知识库较少，无法直接回答您的问题，换个问题试试吧 ";
        } else {
            return result.toString();
    }
}

}
